package com.zh.note.huawei.onehundred.比赛评分;

import java.util.*;

/**
 * @Author: zhanghuan
 * @date: 2023/9/4 20:40
 * @description: create it
 * 4,5
 * 10,6,9,7,6
 * 9,10,6,7,5
 * 8,10,6,5,10
 * 9,10,8,4,9
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(",");
        int judge = Integer.parseInt(line[0]);
        int player = Integer.parseInt(line[1]);
        if (judge < 3 || judge > 10) {
            System.out.println(-1);
            return;
        }
        if (player < 3 || player > 100) {
            System.out.println(-1);
            return;
        }
        List<String[]> list = new ArrayList<>();
        for (int i = 0; i < judge; i++) {
            list.add(sc.nextLine().split(","));
        }

        List<Player> players = new ArrayList<>();
        for (int i = 0; i < player; i++) { // 第i个选手
            int total = 0;
            List<Integer> scoresList = new ArrayList<>();

            for (int j = 0; j < judge; j++) { // 第j个裁判
                String[] strings = list.get(j);
                int score = Integer.parseInt(strings[i]);
                if (score < 0 || score > 10) {
                    System.out.println(-1);
                    return;
                }
                scoresList.add(score);
                total += score;
            }
            players.add(new Player(i, total, scoresList));
        }
        Collections.sort(players, new Comparator<Player>() {
            @Override
            public int compare(Player o1, Player o2) {
                if (o1.total != o2.total) {
                    return o2.total - o1.total;
                }
                List<Integer> sores1 = o1.sores;
                List<Integer> sores2 = o2.sores;
                //总分相同，比较10分的数量，如果10的数量相同，则比较9分的数量，以此类推
                for (int i = 10; i > 0; i--) {
                    int comp1 = compareHighScore(sores1, i);
                    int comp2 = compareHighScore(sores2, i);
                    return comp2 - comp1;
                }
                return 0;
            }

        });
        for (int i = 0; i < 3; i++) {
            if (i == 2) {
                System.out.println(players.get(i).id + 1);
            } else {
                System.out.print(players.get(i).id + 1 + ",");
            }
        }


    }

    private static int compareHighScore(List<Integer> scores, int score) {
        int count = (int) scores.stream().filter(s -> s.equals(score)).count();
        return count;
    }

    static class Player {
        private int id;
        private int total;
        private List<Integer> sores;

        public Player(int id, int total, List<Integer> sores) {
            this.id = id;
            this.total = total;
            this.sores = sores;
        }
    }
}
